package com.springsummer.information.green.hello;

import com.alibaba.fastjson.JSON;

import com.springsummer.information.green.annotation.Controller;
import com.springsummer.information.green.annotation.RequestMapping;
import com.springsummer.information.green.annotation.ResponseBody;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

@Controller
public class HelloStudentController {

    @RequestMapping(path = "/student/add")
    @ResponseBody
    public StudentVo studentAdd(String name, Integer age, String phone){
        //访问地址 http://localhost:8080/student/add?name=pingping&age=18&phone=123456789
        StudentVo userVo=new StudentVo();
        userVo.setStudentName("name:"+name);
        userVo.setAge(age);
        userVo.setPhone("phone:"+phone);
        userVo.setTeacherName("萍萍");
        System.out.println(getClass().getName()+" helloModel model:"+ JSON.toJSONString(userVo));
        return userVo;
    }

    @RequestMapping(path = "/student/list")
    @ResponseBody
    public StudentVo studentList(String name, Integer age, String phone){
        StudentVo userVo=new StudentVo();
        userVo.setStudentName("helloTwo:"+name);
        userVo.setAge(age);
        userVo.setPhone("helloTwo:"+phone);
        userVo.setTeacherName("萍萍");
        System.out.println(getClass().getName()+" helloUserTwo model:"+ JSON.toJSONString(userVo));
        return userVo;
    }

    @RequestMapping(path = "/student/studentViewPage")
    public ModelAndView studentViewPage(String name, Integer age, String phone){
        InternalResourceViewResolver viewResolver;

        StudentVo userVo=new StudentVo();
        userVo.setStudentName("helloTwo:"+name);
        userVo.setAge(age);
        userVo.setPhone("helloTwo:"+phone);
        userVo.setTeacherName("萍萍");
        System.out.println(getClass().getName()+" studentViewPage model:"+ JSON.toJSONString(userVo));
        ModelAndView modelAndView=new ModelAndView("/static/studentView");
        //modelAndView.addObject("namestr",userVo.getStudentName());
        return modelAndView;
    }

    @RequestMapping(path = "/student/studentViewPageRetwo")
    public ModelAndView studentViewPageRetwo(String name, Integer age, String phone){
        InternalResourceViewResolver viewResolver;

        StudentVo userVo=new StudentVo();
        userVo.setStudentName("helloTwo:"+name);
        userVo.setAge(age);
        userVo.setPhone("helloTwo:"+phone);
        userVo.setTeacherName("萍萍");
        System.out.println(getClass().getName()+" studentViewPage model:"+ JSON.toJSONString(userVo));
        ModelAndView modelAndView=new ModelAndView("redirect:/static/studentView");
        //modelAndView.addObject("namestr",userVo.getStudentName());
        return modelAndView;
    }

}
